﻿Imports Microsoft.Practices.Composite.UnityExtensions
Imports Microsoft.Practices.Composite.Modularity
Imports Microsoft.Practices.Composite.Wpf.Regions
Imports Infragistics.Windows.Ribbon
Imports Hinshelwood.TFSStickyBuddy.Infrastructure
Imports Hinshelwood.TFSStickyBuddy.Infrastructure.RegionAdapters
Imports Microsoft.Practices.Unity
Imports Infragistics.Windows.DockManager

Public Class TFSStickyBuddyBootstrapper
    Inherits UnityBootstrapper

    Private m_logger As New EntLibLoggerAdapter

    Protected Overrides Function GetModuleEnumerator() As Microsoft.Practices.Composite.Modularity.IModuleEnumerator
        Dim StaticModuls As New StaticModuleEnumerator()
        ' Add all modules
        StaticModuls.AddModule(GetType(Hinshelwood.TFSStickyBuddy.Modules.ThemeModule))
        StaticModuls.AddModule(GetType(Hinshelwood.TFSStickyBuddy.Modules.TeamSystemModule), "ThemeModule", "LogInModule")
        StaticModuls.AddModule(GetType(Hinshelwood.TFSStickyBuddy.Modules.AreaIterationModule), "TeamSystemModule", "ThemeModule", "LogInModule")
#If DEBUG Then
        StaticModuls.AddModule(GetType(Hinshelwood.TFSStickyBuddy.Modules.CodeplexProjectModule), "ThemeModule", "LogInModule")
        StaticModuls.AddModule(GetType(Hinshelwood.TFSStickyBuddy.Modules.LogInModule))
        StaticModuls.AddModule(GetType(Hinshelwood.TFSStickyBuddy.Modules.KanbanModule), "TeamSystemModule", "ThemeModule", "LogInModule")
#End If
        ' Return modules list
        Return StaticModuls
    End Function

    Protected Overrides ReadOnly Property LoggerFacade() As Microsoft.Practices.Composite.Logging.ILoggerFacade
        Get
            Return m_logger
        End Get
    End Property

    Protected Overrides Sub InitializeModules()
        MyBase.InitializeModules()
    End Sub

    Protected Overrides Sub ConfigureContainer()
        Container.RegisterType(Of IShellView, Shell)()
        Container.RegisterType(Of IShellPresenter, ShellPresenter)(New ContainerControlledLifetimeManager())
        Container.RegisterType(Of INavigationService, Services.NavigationService)()
        Container.RegisterType(Of IContentService, Services.ContentService)()
        MyBase.ConfigureContainer()
    End Sub

    Protected Overrides Function ConfigureRegionAdapterMappings() As Microsoft.Practices.Composite.Wpf.Regions.RegionAdapterMappings
        Dim mappings As RegionAdapterMappings = MyBase.ConfigureRegionAdapterMappings()
        mappings.RegisterMapping(GetType(XamRibbon), New RibbonRegionAdapter())
        mappings.RegisterMapping(GetType(RibbonTabItem), New RibbonTabItemRegionAdapter())
        mappings.RegisterMapping(GetType(ContextualTabGroup), New ContextualTabGroupRegionAdapter())
        mappings.RegisterMapping(GetType(XamDockManager), New DockManagerRegionAdapter())
        mappings.RegisterMapping(GetType(DocumentContentHost), New DocumentContentHostRegionAdapter())
        mappings.RegisterMapping(GetType(SplitPane), New SplitPaneRegionAdapter())
        mappings.RegisterMapping(GetType(TabGroupPane), New TabGroupPaneRegionAdapter())
        mappings.RegisterMapping(GetType(RibbonGroup), New RibbonGroupRegionAdapter())
        mappings.RegisterMapping(GetType(Grid), New GridRegionAdapter())
        'mappings.RegisterMapping(GetType(ApplicationMenu), New ApplicationMenuRegionAdapter())
        Return mappings
    End Function

    Protected Overrides Function CreateShell() As System.Windows.DependencyObject
        Dim presenter As IShellPresenter = Container.Resolve(Of IShellPresenter)()
        presenter.View.ShowView()
        '-----------------
        ''''''''''''''''''
        Return presenter.View
    End Function


End Class
